package com.database.bean;

import javax.persistence.AttributeOverride;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Min;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@Table(name="AGENTTYPE_COMPANYPRODUCT")
@AttributeOverride( name="id", column = @Column(name="id") )
@XmlRootElement
public class AgentTypeCompanyProduct extends BaseBean{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@ManyToOne
	@JoinColumn(name="agenttype_id")
	private AgentType agentType=null;   
	
	@ManyToOne
    @JoinColumn(name="companyproduct_id")
	private CompanyProduct companyProduct=null;
	
	@Min(0)
	@Column(name="amountSold", columnDefinition="default '0'")
	private Integer amountSold=null;

	public AgentTypeCompanyProduct(){}
	
	/**
	 * @return the agentType
	 */
	public AgentType getAgentType() {
		return agentType;
	}

	/**
	 * @param agentType the agentType to set
	 */
	public void setAgentType(AgentType agentType) {
		this.agentType = agentType;
	}

	/**
	 * @return the companyProduct
	 */
	public CompanyProduct getCompanyProduct() {
		return companyProduct;
	}

	/**
	 * @param companyProduct the companyProduct to set
	 */
	public void setCompanyProduct(CompanyProduct companyProduct) {
		this.companyProduct = companyProduct;
	}

	/**
	 * @return the amountSold
	 */
	public Integer getAmountSold() {
		if(this.amountSold==null){
			return 0;
		}
		return amountSold;
	}

	/**
	 * @param amountSold the amountSold to set
	 */
	public void setAmountSold(Integer amountSold) {
		this.amountSold = amountSold;
	}
	
	public void increaseAmountSold(){
		this.amountSold++;
	}

	@Override
	public String toString() {
		return "AgentTypeCompanyProduct [agentType=" + agentType
				+ ", companyProduct=" + companyProduct + ", amountSold="
				+ amountSold + "]";
	}
	
}
